﻿using Core.CurrentFramework.infrastructure;
using Core.CurrentFramework.Repository.Entity;
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace Core.CurrentFramework.Service
{
    public class UserManagement : DBBaseCore, IUserManagement
    {
        private readonly CurrentDbContext context;

        public UserManagement(CurrentDbContext context) : base(context)
        {
            this.context = context;
        }


        public int RigsterUser(UsersInfo user)
        {
            //进行身份信息唯一验证
            var modelVerify = base.GetModel<UsersInfo>(x => x.FUserName == user.FUserName || x.FIdCardNo == user.FIdCardNo || x.FEmail == user.FEmail || x.FMobile == user.FMobile);
            if (modelVerify != null)
            {
                return 0;
            }
            user.FDateTime = DateTime.Now;
            user.FUserPwd = MD5Helper.MD5Encrypt64(user.FUserPwd);
            return base.Add<UsersInfo>(user);
        }


        public bool LoginUser(string Email, string UserPwd)
        {
            return base.GetModel<UsersInfo>(x => x.FUserPwd == MD5Helper.MD5Encrypt64(UserPwd) && (x.FEmail == Email || x.FMobile == Email)) != null;
        }
    }
}
